package scala.test_class.test_simple

/**
 * @author 黄海峰 2021/4/15 17:40
 * */
class PointTwo {
  private var _x = 0
  private var _y = 0
  private val bound = 100

  def x = _x

  private def printWarning(newValue: Int): Unit = println("【%s】Out of bounds".format(newValue))

  def x_=(newValue: Int): Unit = {
    if (newValue < bound) _x = newValue else printWarning(newValue)
  }

  def y = _y

  def y_=(newValue: Int): Unit = {
    if (newValue < bound) _y = newValue else printWarning(newValue)
  }

  override def toString: String = s"($x,$y)"
}

/**
 * the private data is stored in private variables _x and _y.
 * There are methods def x and def y for accessing the private data.
 * def x_= and def y_= are for validating and setting the value of _x and _y.
 *
 * Notice the special syntax for the setters:
 * the method has _= appended to the identifier of the getter and the parameters come after.
 */